var moduleCode = getQueryString("moduleCode");
var moduleNo = getQueryString("moduleNo");
$(function () {
    var queryParam = '';
    if(moduleCode){
        queryParam = 'moduleCode=' + moduleCode;
    }
    if(moduleNo){
        queryParam += (queryParam?'&':'' + 'moduleNo=' + moduleNo);
    }
    var queryUrl = '../modulpositioncorrelation/moduleCostStat';
    if(queryParam){
        queryUrl += '?' + queryParam;
    }
    $("#jqGrid").Grid({
        url: queryUrl,
        rownumWidth: 35,
        height: 425,
        rowNum: 1000,
        rowList:[],
        colModel: [
            {label: 'id', name: 'id', key: true, hidden: true},
            {label: '模具编码', name: 'moduleCode', hidden: true},
            {label: '关联备件名称', name: 'positionName'},
            {label: '单价', name: 'price'},
            {label: '平均更换寿命', name: 'avgLife'},
            {label: '更换个数', name: 'replaceNum'},
            {label: '成本(元)', name: 'cost',summaryType:'sum', summaryTpl:'<b>成本总计: {0}</b>'}
        ],
        grouping:true,
        groupingView : {
            groupField : ['moduleCode'],
            groupSummary : [true],
            groupColumnShow : [false],
            groupText : ['<b>模具[{0}]年度成本统计</b>'],
            groupCollapse : false
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        q: {
            moduleCode: moduleCode, // 模具编码
            moduleNo: moduleNo, // 模具号
            year: '' // 统计年份
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        getInfo: function (id) {
            Ajax.request({
                url: "../modulpositioncorrelation/info/" + id,
                async: true,
                successCallback: function (r) {
                    vm.modulPositionCorrelation = r.modulPositionCorrelation;
                }
            });
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: vm.q,
                page: page
            }).trigger("reloadGrid");
        },
        reloadSearch: function () {
            vm.q.year = '';
            vm.reload();
        },
        convertGMT2Year: function(time){
            return new Date(time).getFullYear();
        },
        showPosMonthlyCostItem: function () {
            // 查看关联位置月度成本明细
            var id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            openWindow({
                type: 2,
                title: '<i class="fa fa-bars"></i> 关联位置成本统计',
                content: '../module/modulePositionCorrelationCostStat.html?year=' + vm.q.year + '&moduleCorrelationPositionId=' + id
            })

        }
    }
});
